package iotest;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class J_DataStream {
	public static void main(String[] args) {
		FileInputStream fileInputStream;
		FileOutputStream fileOutputStream;
		DataOutputStream dataOutputStream = null;
		DataInputStream dataInputStream = null;
		try {
			fileOutputStream = new FileOutputStream("out.txt");
			dataOutputStream = new DataOutputStream(fileOutputStream);
			int i;
			for (i = 0; i < 4; i++) {
				dataOutputStream.writeInt('0'+i);
			}

			fileInputStream = new FileInputStream("out.txt");
			dataInputStream = new DataInputStream(fileInputStream);
			for (i = 0; i < 4; i++) {
				System.out.print(dataInputStream.readInt() + "\n");
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (dataInputStream != null) {
					dataInputStream.close();
				}
				if (dataOutputStream != null) {
					dataOutputStream.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
